package com.ruoyi.comn.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.comn.domain.ComnUserGroup;
import com.ruoyi.comn.service.IComnUserGroupService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 人员分组Controller
 * 
 * @author ruoyi
 * @date 2021-11-29
 */
@RestController
@RequestMapping("/userGroup")
public class ComnUserGroupController extends BaseController
{
    @Autowired
    private IComnUserGroupService comnUserGroupService;

    /**
     * 查询人员分组列表
     */
    @PreAuthorize(hasPermi = "comn:userGroup:list")
    @GetMapping("/list")
    public TableDataInfo list(ComnUserGroup comnUserGroup)
    {
        startPage();
        List<ComnUserGroup> list = comnUserGroupService.selectComnUserGroupList(comnUserGroup);
        return getDataTable(list);
    }

    /**
     * 导出人员分组列表
     */
    @PreAuthorize(hasPermi = "comn:userGroup:export")
    @Log(title = "人员分组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComnUserGroup comnUserGroup) throws IOException
    {
        List<ComnUserGroup> list = comnUserGroupService.selectComnUserGroupList(comnUserGroup);
        ExcelUtil<ComnUserGroup> util = new ExcelUtil<ComnUserGroup>(ComnUserGroup.class);
        util.exportExcel(response, list, "人员分组数据");
    }

    /**
     * 获取人员分组详细信息
     */
    @PreAuthorize(hasPermi = "comn:userGroup:query")
    @GetMapping(value = "/{userGroupUuid}")
    public AjaxResult getInfo(@PathVariable("userGroupUuid") String userGroupUuid)
    {
        return AjaxResult.success(comnUserGroupService.selectComnUserGroupByUserGroupUuid(userGroupUuid));
    }

    /**
     * 新增人员分组
     */
    @PreAuthorize(hasPermi = "comn:userGroup:add")
    @Log(title = "人员分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComnUserGroup comnUserGroup)
    {
        return toAjax(comnUserGroupService.insertComnUserGroup(comnUserGroup));
    }

    /**
     * 修改人员分组
     */
    @PreAuthorize(hasPermi = "comn:userGroup:edit")
    @Log(title = "人员分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComnUserGroup comnUserGroup)
    {
        return toAjax(comnUserGroupService.updateComnUserGroup(comnUserGroup));
    }

    /**
     * 删除人员分组
     */
    @PreAuthorize(hasPermi = "comn:userGroup:remove")
    @Log(title = "人员分组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userGroupUuids}")
    public AjaxResult remove(@PathVariable String[] userGroupUuids)
    {
        return toAjax(comnUserGroupService.deleteComnUserGroupByUserGroupUuids(userGroupUuids));
    }
}
